package ai.llz.ai_pro;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.dictionary.CustomDictionary;
import com.hankcs.hanlp.seg.Segment;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.Scanner;

@Configuration
public class TableConfig {
    @Bean
    Segment getSegment() throws IOException {
        Segment segment = HanLP.newSegment().enableCustomDictionary(true);
        ClassPathResource classPathResource = new ClassPathResource("custom/ai_pro_table.csv");
        Scanner scanner = new Scanner(classPathResource.getInputStream());
        while (scanner.hasNext()){
            String next = scanner.next();
            CustomDictionary.add(next,"nrf");
        }
        CustomDictionary.add("出生日期","n");
        scanner.close();
        return segment;
    }
}
